package com.java.simple.smallmybatis.session.defaults;

import com.java.simple.smallmybatis.binding.MapperRegistry;
import com.java.simple.smallmybatis.session.SqlSession;
import lombok.RequiredArgsConstructor;

/**
 * @author zhoujunlin
 * @date 2022年12月22日 15:13
 * @desc
 */
@RequiredArgsConstructor
public class DefaultSqlSession implements SqlSession {

    /**
     * 映射器注册器
     */
    private final MapperRegistry mapperRegistry;

    @Override
    public <T> T selectOne(String statement) {
        return (T) ("你被代理了！" + statement);
    }

    @Override
    public <T> T selectOne(String statement, Object parameter) {
        return (T) ("你被代理了, stmt：" + statement + " 入参：" + parameter);
    }

    @Override
    public <T> T getMapper(Class<T> type) {
        return mapperRegistry.getMapper(type, this);
    }
}
